﻿using GameEditor.View;
using GameEditor.View.Components;
using PureMVC.Interfaces;
using PureMVC.Patterns;
using GameEngine.View.Components;
using System;
using GameEngine.Model;
using GameEngine;

namespace GameEditor.Commands
{
    /// <summary>
    /// 
    /// </summary>
    public class CreateWorldEditor_Command<MyIdType> : SimpleCommand
        where MyIdType : IComparable<MyIdType>
    {
        override public void Execute(INotification notification)
        {
            if (notification.Body == null)
                throw new Exception(this.GetType().Name + " has to have body");

            var dataProxy = notification.Body as IWorldDataProxy<MyIdType>;

            var editorMediator = GameEditorViewFacade<MyIdType>.Instance.
                CreateWorldEditorMenuMediator(
                GameEditorFacade.WorldEditorMediatorName,
                GameEditorViewFacade<MyIdType>.Instance.CreateWorldEditorMenuView(),
                dataProxy
                );

            
            Facade.RegisterMediator(editorMediator);
            editorMediator.WorldName = dataProxy.WorldName;
            editorMediator.WorldId = dataProxy.VO.Id;
            foreach(var thingType in ModelFacade<MyIdType>.Instance.Game.ThingTypes.Keys)
                editorMediator.AddThingType(thingType);
            foreach (var thing in dataProxy.Items)
                editorMediator.AddThing(thing.Key);
        }
    }
}
